package threading;

public class Demo19 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(()-> {
            while(true) {
                synchronized (object) {
                    try {
                        System.out.println("wait之前");
                        object.wait();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("wait 之后");
                }
            }
        });
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Thread t2 = new Thread(()-> {
            while (true) {
                synchronized (object) {
                    System.out.println("notify 之前");
                    object.notify();
                    System.out.println("notify 之后");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
